package day9;

import org.junit.Test;

import javax.xml.crypto.Data;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Date;

public class User {
    private Integer id;
    private Date doTime;
    private SimpleDateFormat sdf = new SimpleDateFormat();
    private LocalDate birthday;

    @Test
    public void testDate(){
        Date date = new Date();
        System.out.println(date);
        System.out.println(date.getYear());
        System.out.println(date.getMonth());
    }


    @Test
    public void testFormate() throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
        //设定 一个日期的预定义格式
        sdf.applyPattern("yyyy-MM-dd");
        Date date = new Date();;
        //日期转成字符串
        String format = sdf.format(date);
        System.out.println(format);
        sdf.applyPattern("yyyy'年'MM'月'dd'日' HH:mm:ss");
        format = sdf.format(date);;
        System.out.println(format);

        String v1="2025年09月11日 23:59:59";
        //字符串转date
        Date parse = sdf.parse(v1);
        System.out.println(parse);

    }


    @Test
    public void init(){
        LocalDate now = LocalDate.now();
        //2025-08-11
        System.out.println(now);
        //指定日期
        LocalDate of = LocalDate.of(2025, 9, 11);
        //2025-09-11
        System.out.println(of);
    }

    @Test
    public void parse(){
        LocalDate now = LocalDate.now();

        String v1 = now.format(DateTimeFormatter.ofPattern("yyyy'年'MM'月'dd'日'"));
        //2025年08月11日
        System.out.println(v1);

        String v2="2026/09/01";
        LocalDate date2 = LocalDate.parse(v2, DateTimeFormatter.ofPattern("yyyy/MM/dd"));
        //2026-09-01
        System.out.println(date2);
    }

    @Test
    public void count(){
        //2025-08-11
        LocalDate now = LocalDate.now();
        LocalDate v1 = now.plusDays(10);
        // 2025-08-21
        System.out.println(v1);

        //2026-08-11
        LocalDate v2 = now.plusYears(1);
        System.out.println(v2);

        //在月份的字段上加上3天
        //2025-11-11
        LocalDate v3 = now.plus(3, ChronoUnit.MONTHS);
        System.out.println(v3);

        //2025-09-10
        LocalDate v4 = now.plus(30, ChronoUnit.DAYS);
        System.out.println(v4);

    }
}
